const { sequelize } = require("../../core/db");
const { Sequelize, Model } = require("sequelize");

class Order extends Model {}

Order.init(
  {
    order_id: {
      type: Sequelize.INTEGER,
      primaryKey: true,
      autoIncrement: true,
    },
    uid: {
      type: Sequelize.INTEGER,
      comment: "用户id",
    },
    order_number: {
      type: Sequelize.STRING,
      comment: "抽奖订单编号",
      defaultValue: () => {
        return "DLR" + Date.now() + "" + Math.floor(Math.random() * 10000);
      },
    },
    address: {
      type: Sequelize.STRING,
      comment: "收货地址",
    },
    order_status: {
      type: Sequelize.INTEGER,
      defaultValue: 0, // 0：待发货，1：已发货，2：已完成
      comment: "订单状态",
    },
    tracking_number: {
      type: Sequelize.STRING,
      comment: "快递单号",
    },
    order_amount: {
      type: Sequelize.DECIMAL(10, 2),
      comment: "订单金额",
    },
    goods_id: {
      type: Sequelize.STRING,
      comment: "商品id",
    },
    goods_details: {
      type: Sequelize.TEXT,
      comment: "商品详情",
    },
    order_remark: {
      type: Sequelize.STRING,
      comment: "订单备注",
    },
  },
  {
    sequelize,
    tableName: "order",
  }
);

module.exports = {
  Order,
};
